const res = require('express/lib/response');
const dao= require('../../dao/daoenter.js');
const result= require('../../util/result/result.js');


/* 添加职业类型 */
    async function addProfessionType(req,res){
        /*
        前端数据格式
        professionTypeName  String
        professionTypeDesc  String
        */
       let ca1={}
       ca1.professionTypeName=req.body.professionTypeName
       ca1.professionTypeDesc=req.body.professionTypeDesc

       console.log(ca1,888);
        let dd= await  dao.daoProfessionType.daoprofessionTypeAdd(ca1)
        console.log(dd,666666);
        if(dd){
            res.send(result.result(true,dd))
        }else{
            res.send(result.result(false))
        }
    }

    /* 查询所有职业类型 */
    async function findAllprofessionType(req,res){
            let cc=await dao.daoProfessionType.daofindAllType()
            if(cc){
                res.send(result.result(true,cc))
            }else{
                res.send(result.result(false))
            }
    }

    /* 
    修改职业类型
    //职业名
		professionTypeName:String,
	   //职业描述
	   professionTypeDesc:String
    */
    async function proTypeUpdate(req,res){
        // console.log(req.body,6666666666666);
            /* 矫正数据 */
            let typeid=req.body.typeid
            let obj={}
            obj.professionTypeName=req.body.professionTypeName
            obj.professionTypeDesc=req.body.professionTypeDesc
            try {
                let cc=await dao.daoProfessionType.proTypeUpdateDao(typeid,obj)
                if(cc){
                    res.send(result.result(true,cc))
                }else{
                    res.send(result.result(false))
                }
            } catch (error) {
                res.send(result.result(false)) 
            }
}
   
    /* 
    删除职业类型
     */
    async function proTypeDelete(req,res){
        console.log(req.body,132323);
        let id=req.body.typeid
  
        try {
            let cc=await dao.daoProfessionType.proTypeDeleteDao(id)
            if(cc){
                res.send(result.result(true,cc))
            }else{
                res.send(result.result(false))
            }
        } catch (error) {
            res.send(result.result(false)) 
        }
    }


module.exports={
	addProfessionType,findAllprofessionType,proTypeDelete,proTypeUpdate
}
